<template>
  <div class="container">
    <div class="app-container">
      <div class="left">
        <el-input style="margin-bottom:10px" type="text" prefix-icon="el-icon-search" size="small" placeholder="输入员工姓名全员搜索" />
        <!-- 树形组件 -->
        <el-tree
          ref="tree"
          :data="list"
          :props="defaultProps"
          default-expand-all
          :highlight-current="true"
          node-key="id"
          :expand-on-click-node="false"
        />
      </div>
      <div class="right">
        <el-row class="opeate-tools" type="flex" justify="end">
          <el-button size="mini" type="primary">添加员工</el-button>
          <el-button size="mini">excel导入</el-button>
          <el-button size="mini">excel导出</el-button>
        </el-row>
        <!-- 表格组件 -->
        <el-table :data="tableData">
          <el-table-column
            label="头像"
          />
          <el-table-column
            label="姓名"
            prop="username"
          />
          <el-table-column
            label="手机号"
            sortable
            prop="mobile"
          />
          <el-table-column
            label="工号"
            sortable
            prop="workNumber"
          />
          <el-table-column
            label="聘用形式"
            prop="formOfEmployment"
          >
            <template v-slot="{row}">
              <span v-if="row.formOfEmployment===1">正式</span>
              <span v-else-if="row.formOfEmployment===2">非正式</span>
              <span v-else>无</span>
            </template>
          </el-table-column>
          <el-table-column
            label="部门"
            prop="departmentName"
          />
          <el-table-column
            label="入职时间"
            prop="timeOfEntry"

            sortable
          />
          <el-table-column
            label="操作"
          >
            <template>
              <el-row type="flex">
                <el-button type="text">查看</el-button>
                <el-button type="text">角色</el-button>
                <el-button type="text">删除</el-button>
              </el-row>
            </template>
          </el-table-column>
        </el-table>
        <!-- 分页 -->
      </div>
    </div>
  </div>
</template>

<script>
import { getDashboard } from '@/api/department'
import { getEmployeeList } from '@/api/employee'
import { transListToTreeData } from '@/utils/index'
export default {
  name: 'Employee',
  data() {
    return {
      list: [], // 装树形数据
      defaultProps: {
        children: 'children',
        label: 'name'
      },
      tableData: [], // 装表单是数据
      params: {
        page: 1, // 当前页数
        pagesize: 10, // 当前页面需要的数据条数
        keyword: '', // 模糊搜索
        departmentId: null
      },
      total: null
    }
  },
  created() {
    this.getDashboard()
  },
  methods: {
    async getDashboard() {
      this.list = transListToTreeData(await getDashboard(), 0)
      this.$nextTick(() => {
        this.$refs.tree.setCurrentKey(this.list[0].id)
      })
      this.params.departmentId = this.list[0].id // 调接口的时候，默认调第一个
      const { rows, total } = await getEmployeeList(this.params)
      this.tableData = rows
      this.total = total
    }
  }
}
</script>

<style lang="scss" scoped>
.app-container {
  background: #fff;
  display: flex;
  .left {
    width: 280px;
    padding: 20px;
    border-right: 1px solid #eaeef4;
  }
  .right {
    flex: 1;
    padding: 20px;
    .opeate-tools {
      margin:10px ;
    }
    .username {
      height: 30px;
      width: 30px;
      line-height: 30px;
      text-align: center;
      border-radius: 50%;
      color: #fff;
      background: #04C9BE;
      font-size: 12px;
      display:inline-block;
    }
  }
}

</style>
